<template>
  <div class="wrapper">
    <div
      class="goods_item"
      v-for="item in productList"
      :key="item.id"
      @click="goDetail(item)"
    >
      <div
        class="pic"
        :style="{ width: picBox?.width + 'px', height: picBox?.height + 'px' }"
      >
        <el-image :src="item.image" fit="scale-down">
          <div slot="placeholder" class="image-slot">
            loading<span class="dot">...</span>
          </div>
        </el-image>
      </div>
      <div class="goods_content">
        <div class="store_name lines2">
          {{ item.storeName }}
        </div>
        <div class="acea-row row-between">
          <div class="price">
            <statistic :value="item.price" :currency="item.currency" />
          </div>
          <div v-if="item.sales" class="sold">
            {{ Math.floor(item.sales) + Math.floor(item.ficti) || 0 }}
            {{ $t(`page.goodsDetail.sold`) }}
          </div>
          <div
            v-if="item.isFollow"
            @click.stop="collect(item)"
            class="follow"
            :class="item.isFollow ? 'bg-color' : ''"
          >
            <span
              class="iconfont"
              :class="item.isFollow ? 'icon-xihuan1' : 'icon-guanzhu'"
            ></span>
          </div>
        </div>
        <div class="ot_price">
          <statistic
            :valueStyle="{ color: '#999', textDecoration: 'line-through' }"
            :value="item.otPrice"
            :currency="item.currency"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { followPro, goShopDetail } from "@/utils/order.js";
export default {
  name: "goodsList",
  props: {
    productList: {
      type: Array,
      default: function () {
        return [];
      },
    },
    picBox: {
      type: Object,
      default: function () {
        return null;
      },
    },
  },
  methods: {
    goDetail(item) {
      console.log("修改处", item);
      goShopDetail(item.productId, this);
      // goShopDetail(item.id, this)
    },
    /**
     *
     * 收藏 | 取消收藏
     */
    collect(item) {
      if (!this.$auth.loggedIn) {
        this.$store.commit("isLogin", true);
      } else {
        followPro(this, item.isFollow, item.productId).then(() => {
          // this.$set(item, 'isFollow', !item.isFollow);
          this.$emit('updateProductList',item)
        });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/css/variables.scss";
.sold {
  font-size: 12px;
  color: #999999;
  margin-right: 15px;
}
.ot_price {
  font-size: 12px;
  font-weight: 400;
  color: #888888;
  line-height: 12px;
  display: flex;
  justify-content: space-between;
  margin-right: 20px;
  text-decoration: line-through;

  .lines {
    text-decoration: line-through;
  }
}
.icon-xihuan1 {
  color: #fff;
}
.wrapper {
  // width:975px;
  background-color: #fff;
  // padding: 0 0 30px 0;
}
.goods_item {
  width: 208px;
  display: inline-block;
  margin: 0 16px 18px 0;
  cursor: pointer;
  .pic {
    width: 208px;
    height: 208px;

    .el-image {
      border-radius: 8px;
      border: 1px solid #d9dfe7;
      width: 100%;
      height: 100%;
    }
    &:hover {
      .img,
      .el-image {
        box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.2);
      }
    }
  }
  .goods_content {
    .store_name {
      height: 44px;
      margin: 7px 0 10px 0;
      font-size: 16px;
      font-family: ArialMT;
      color: #333333;
    }
    .lines2 {
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }

  .acea-row {
    .price {
      font-size: 18px;
      font-family: DINCond-Black, DINCond;
      font-weight: 900;
      color: $user--color-price;
      line-height: 20px;
      margin-bottom: 9px;
    }
    .follow {
      width: 25px;
      height: 25px;
      line-height: 25px;
      background: #f1f1f1;
      border-radius: 50%;
      cursor: pointer;
      .iconfont {
        margin: auto;
        margin-left: 5px;
        font-size: 14px;
      }
    }
  }
}
</style>
